﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using KM.ENT;

namespace KM.DAT
{
    public class datLoaiKhuyenMai
    {
        public datLoaiKhuyenMai()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        SqlCommand cmd;
        SqlDataReader dr;
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
        public void insert(entLoaiKhuyenMai entLKM)
        {
            SqlConnection sqlConnection = new SqlConnection(constr);
            sqlConnection.Open();
            cmd = new SqlCommand("sp_LoaiKhuyenMaiInsert", sqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] sqla = new SqlParameter[1];
            sqla[0] = new SqlParameter("TenLoaiKhuyenMai", DbType.Int32);

            sqla[0].Value = entLKM.TenLoaiKhuyenMai;


            cmd.Parameters.AddRange(sqla);
            cmd.ExecuteNonQuery();
            sqlConnection.Close();
        }
        public List<entLoaiKhuyenMai> getAll()
        {
            
            SqlConnection sqlConnection = new SqlConnection(constr);
            sqlConnection.Open();
            cmd = new SqlCommand("sp_LoaiKhuyenMaiGetAll", sqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;

            dr = cmd.ExecuteReader();
            entLoaiKhuyenMai entLKM = new entLoaiKhuyenMai();
            List<entLoaiKhuyenMai> lst = new List<entLoaiKhuyenMai>();
            while (dr.Read())
            {
                entLKM = new entLoaiKhuyenMai();
                entLKM.LoaiKhuyenMaiId = Convert.ToInt32(dr["LoaiKhuyenMaiId"].ToString());
                entLKM.TenLoaiKhuyenMai = dr["TenLoaiKhuyenMai"].ToString();

                lst.Add(entLKM);
            }
            dr.Close();
            sqlConnection.Close();
            return lst;
        }
        public entLoaiKhuyenMai getInfo(entLoaiKhuyenMai entLKMTS)
        {
            SqlConnection sqlConnection = new SqlConnection(constr);
            sqlConnection.Open();
            cmd = new SqlCommand("sp_LoaiKhuyenMaiGetInfo", sqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] sqla = new SqlParameter[1];
            sqla[0] = new SqlParameter("LoaiKhuyenMaiId", DbType.Int32);
            sqla[0].Value = entLKMTS.LoaiKhuyenMaiId;

            cmd.Parameters.AddRange(sqla);
            dr = cmd.ExecuteReader();
            entLoaiKhuyenMai entLKM = new entLoaiKhuyenMai();
            if (dr.Read())
            {
                entLKM.LoaiKhuyenMaiId = Convert.ToInt32(dr["LoaiKhuyenMaiId"].ToString());
                entLKM.TenLoaiKhuyenMai = dr["TenLoaiKhuyenMai"].ToString();

            }
            dr.Close();
            sqlConnection.Close();
            return entLKM;
        }
        public void edit(entLoaiKhuyenMai entLKM)
        {
        }

    }
}